<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import axios from 'axios'

const router = useRouter()
const loading = ref(false)
const teachers = ref([])

// 获取所有教师的分析摘要
const fetchTeachers = async () => {
  loading.value = true
  try {
    const res = await axios.get('/api/admin/teacher-analysis/summary-list')
    if (res.data?.code === '200') {
      teachers.value = res.data.data
    }
  } catch (error) {
    console.error('获取教师分析列表失败:', error)
  }
  loading.value = false
}

// 跳转到教师详情页
const goToDetail = (teacherId) => {
  router.push(`/tabus/teacher-analysis/${teacherId}`)
}

onMounted(() => {
  fetchTeachers()
})
</script>

<template>
  <div class="teacher-analysis">
    <div class="page-header">
      <h2>教师分析</h2>
      <p>查看各位教师的教学情绪和课堂表现</p>
    </div>
    
    <el-row :gutter="20" v-loading="loading">
      <el-col :span="8" v-for="teacher in teachers" :key="teacher.teacherId" class="mb-4">
        <el-card class="teacher-card" @click="goToDetail(teacher.teacherId)">
          <template #header>
            <div class="card-header">
              <h3>{{ teacher.teacherName }}</h3>
              <el-tag size="small">{{ teacher.totalCourses || 0 }} 门课程</el-tag>
            </div>
          </template>
          
          <div class="card-content">
            <div class="metrics">
              <div class="metric-item">
                <div class="metric-label">平均快乐值</div>
                <div class="metric-value happy">{{ teacher.avgHappiness?.toFixed(1) || 0 }}</div>
              </div>
              <div class="metric-item">
                <div class="metric-label">平均生气值</div>
                <div class="metric-value anger">{{ teacher.avgAnger?.toFixed(1) || 0 }}</div>
              </div>
              <div class="metric-item">
                <div class="metric-label">平均平静值</div>
                <div class="metric-value neutral">{{ teacher.avgNeutral?.toFixed(1) || 0 }}</div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped>
.teacher-analysis {
  padding: 20px;
  background: #f5f7fa;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h2 {
  margin: 0;
  font-size: 24px;
  color: #000;
}

.page-header p {
  margin: 8px 0 0;
  color: #666;
}

.teacher-card {
  cursor: pointer;
  transition: all 0.3s;
}

.teacher-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.card-header h3 {
  color: #000;
}

.metric-label {
  color: #666;
}

.metric-value {
  color: #000;
  font-weight: 600;
}
.metric-value.happy {
  color: #67C23A;
}
.metric-value.anger {
  color: #F56C6C;
}
.metric-value.neutral {
  color: #909399;
}
</style> 